<?php
class Mcategory_book extends CI_Model{
    
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }

    public function getCategory(){
        $this->db->select(' category_id, book_id');
        $this->db->from('category_book');
        $query = $this->db->get();
        return $query->result_array();
    }

    public function insertCategoryBook($param){
        $data = array(
            'category_id' => $param['category_id'],
            'book_id' => $param['book_id']
        );
        $result = $this->db->insert('category_book', $data);
        print_r($result);
    }

    public function updateCategoryBook($param){
        $data = array(
            'category_id' => $param['category_id'],
        );
        $this->db->where('book_id', $param['book_id']);
        $this->db->update('category_book', $data);
    }

    public function deteleCategoryBook($book_id){
        $this->db->where('book_id', $book_id);
        $this->db->delete('category_book');
    }

    public function getBookByUname($book_uname){
        $this->db->select(' book.id as book_id, book.name as book_name, book.uname as book_uname, book.image_id as book_image, book.author_id as book_author, page_title, page_keyword, 
                            page_description, description, mob_description, book.type as book_type, use_volume, status,
                            author.name as author_name, filename
                         ');
        $this->db->from('book');
        $this->db->join('author'        , 'book.author_id = author.id', 'inner');
        $this->db->join('image'         , 'book.image_id = image.id', 'left');
        $this->db->where("book.uname", $book_uname);
        $query = $this->db->get();
        return $query->row_array();
    }

    public function countCategory(){
        $this->db->select('count(id) as total');
        $this->db->from('category');       
        $query = $this->db->get();
        return $query->row('total');
    }
}
?>